/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bash.carrep.ui;


import com.vaadin.data.util.BeanItem;

import com.vaadin.ui.Form;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Window;
import java.util.List;

/**
 * Abstraction de la classe Form implémentant les fonctions de base.
 * @author bash
 */
public abstract class AbstractFrom extends Form {

    protected Object pojo = null;
    protected BeanItem bi;
    protected Form form = this;
    HorizontalLayout buttons = new HorizontalLayout();
    CarrepApplication app;
    
    protected  EditSaveCancelView standardfooter;

    public AbstractFrom(CarrepApplication app, Class c) {

        this.app = app;
        try {

            pojo = c.newInstance();

        } catch (InstantiationException ex) {
         //hope will never happen 
        } catch (IllegalAccessException ex) {
            ex.printStackTrace(); //can happen !
        }

        bi = new BeanItem(pojo);

        form.setWriteThrough(false); // we want explicit 'apply'
        form.setInvalidCommitted(false); // no invalid values in datamodel
             
       
    }

    public void setFormFieldFactory(com.bash.carrep.ui.util.PojoFieldFactory pff) {
        form.setFormFieldFactory(pff);

    }

    void setVisibleLabels(List<String> l) {
        form.setVisibleItemProperties(l);
    }

    protected void showNotification(String titre, int type, int position, String htmlMessage) {

        Window.Notification n = new Window.Notification(titre, type);
        n.setPosition(position);
        n.setDescription(htmlMessage);

        getWindow().showNotification(n);
    }
    
    

    abstract void initDatasource();

    abstract void buildButtons();

    abstract void submit();

}
